package com.fastloan.mgt.application.repay.web;

import com.fastloan.mgt.application.base.service.ApplicationService;
import com.fastloan.mgt.application.repay.model.ZyApplicationRepaymentPlan;
import com.fastloan.mgt.application.repay.model.vo.AppCurrRepayExt;
import com.fastloan.mgt.application.repay.model.vo.RepayExt;
import com.fastloan.mgt.application.repay.service.ZyApplicationRepaymentPlanService;
import com.fastloan.safe.core.util.ManagerKit;
import com.fastloan.utils.DozerUtil;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by gelon on 2017/11/20.
 */
@RestController
@RequestMapping("/api/zy/web/repayment")
public class WebRepaymentController extends BaseController<ZyApplicationRepaymentPlan> {

    @Autowired
    ApplicationService applicationService;

    @Autowired
    ZyApplicationRepaymentPlanService repaymentPlanService;

    /**
     * 查看当前客户的贷款
     */
    @PostMapping()
    public ResultTo queryMineApp(String customerId) {
        Map<String, Object> map = new HashMap<>();
        map.put("date", new Date());
        map.put("customerId", customerId);
        return dataPage(applicationService, AppCurrRepayExt.class, "queryMineApp", map);
    }


    /**
     * 查看当前客户经理的贷款
     */
    @PostMapping("/managerApp")
    public ResultTo queryCustomerApp(Integer appStatus, String customerName) {
        Map<String, Object> map = new HashMap<>();
        map.put("date", new Date());
        map.put("customerManagerId", ManagerKit.getUserId());
        if (appStatus != null) {
            map.put("appStatus", appStatus);
        }
        if (customerName != null) {
            map.put("customerName", customerName);
        }
        return dataPage(applicationService, AppCurrRepayExt.class, "queryMineApp", map);
    }


    /**
     * 查看进件的还款计划
     */
    @PostMapping("/apprepay")
    public ResultTo apprepay(String appId) {
        Map<String, Object> map = new HashMap<>();
        map.put("appId", appId);
        List<RepayExt> repayExtList = repaymentPlanService.queryByAppId(map);
        return new ResultTo().setData(repayExtList);
    }


}
